#pragma once

template <typename Key, typename Val, bool IsConst>
struct _hIntervalMapIterator
{
	friend class hIntervalMap<Key, Val>;
	friend class hIntervalMapNode<Key, Val>;

	using ThisTy = _hIntervalMapIterator;
	using MapTy = std::conditional_t<IsConst, const hIntervalMap<Key, Val>, hIntervalMap<Key, Val>>;
	using NodeTy = std::conditional_t<IsConst, const hIntervalMapNode<Key, Val>, hIntervalMapNode<Key, Val>>;
	using ValNodeTy = std::conditional_t<IsConst, const hListNode<Val>, hListNode<Val>>;
	using KeyRef = std::reference_wrapper<typename NodeTy::CKeyTy>;
	using ValRef = std::reference_wrapper<std::conditional_t<IsConst, const Val, Val>>;
	using RetPr = std::pair<KeyRef, ValRef>;

private:
	MapTy* _pMap = NULL;
	NodeTy* _pNode = NULL;
	ValNodeTy* _pValNode = NULL;
public:
	_hIntervalMapIterator() {}
	_hIntervalMapIterator(MapTy* pMap, NodeTy* pNode, ValNodeTy* pValNode);

	auto operator->();
	auto operator*();
	auto& operator++();
	auto operator++(int);
	bool operator==(const ThisTy& other) const;
	bool operator!=(const ThisTy& other) const { return !(*this == other); }
};

#include "hIntervalMapIteratorImpl.h"
